<template>
	<view class="driving">
		<image src="/pagesHome/static/images/driving-bg.png"
			style="width:100%;height: 100%;position: absolute;z-index: -1;"></image>
		<view class="p30" style="z-index: 11;">
			<view style="width: 100%;" class="p0 mt20">
				<view class="flex-center">
					<view class="t-box flex-column-center">
						<view class="fw600">
							<view class="f100 mr10 ">{{toFormatVal(drivingDataPoint.carSpeed, [0, 150], 1)}}
							</view>
						</view>
						<view class="cs">
							<view class="f20">当前车速km/h</view>
						</view>
						<image src="/pagesHome/static/images/yb.png" style="width: 356upx;height:356upx"></image>
					</view>
				</view>

				<view class="flex-between" style="padding: 0 20px;">
					<view class="t-box-small flex-column-center">
						<view class=" flex-row baseline  mb8 mt20">
							<view class="f28 mr4 fw600">{{toFormatVal(drivingDataPoint.engineSpeed, [0, 15000], 0)}}
							</view>
							<view class="f12">RPM</view>
						</view>
						<view class="flex-column-center">
							<view class="f20 mb8">实时转速</view>
							<image src="/pagesHome/static/images/zs.png" style="width: 37upx;height:29upx"></image>
						</view>
						<image src="/pagesHome/static/images/yb-small.png" style="width: 240upx;height:240upx"></image>
					</view>

					<view class="t-box-small flex-column-center">
						<view class=" flex-row baseline  mb8 mt20">
							<view class="f28 mr4 fw600">{{toFormatVal(drivingDataPoint.currentOil, [0, 4.5], 1)}}
							</view>
							<view class="f12">L/100km</view>
						</view>
						<view class="flex-column-center">
							<view class="f20 mb8">实时油耗</view>
							<image src="/pagesHome/static/images/yx.png" style="width: 32upx;height:32upx"></image>
						</view>
						<image src="/pagesHome/static/images/yb-small.png" style="width:  240upx;height: 240upx"></image>
					</view>
				</view>
			</view>

			<view class="card-shadow-box p20" style="margin-top: 200rpx;">
				<view class="flex">
					<view class="f20 fw600">续航里程：<view class="mr4 inlineBlock">
							<text style="color:#FD8C05"
								v-if="parseInt(indexDataPoint.surplusOil)<=12">
								{{lt}}
							</text>
							<text v-else>
								{{setNumerRound(enduranceMileage, [10, 450], 0)}}
							</text>
						</view>km</view>
				</view>
				<view class="mt20 mb10">
					<u-line-progress
						:activeColor="setNumerRound(enduranceMileage, [10, 450], 0)<50?'#FD8C05':'rgba(4, 184, 243, 1)'"
						:percentage="setNumerRound(enduranceMileage, [10, 450], 0)/450*100" :showText="false"
						height="15">
					</u-line-progress>
					<!-- <u-line-progress percentage="30" :showText="false"></u-line-progress> -->
				</view>
			</view>

			<view class="flex-row fw600 mt30">
				<view class="yh-box card-shadow-box p20 " style="position: relative;width:196upx">
					<view class="">
						<view class="t-center">平均油耗</view>

						<view >
							<view class="yh">
								<view class="f48 mr10">{{toFormatVal(drivingDataPoint.driveAverageOil, [0, 4.5], 1)}}
								</view>
								<view class="f20">L/100km</view>
							</view>
							<view class="progress-wrapper">
								<u-line-progress activeColor="rgba(4, 184, 243, 1)"
									:percentage="toFormatVal(drivingDataPoint.driveAverageOil, [0, 4.5], 1)/4.5*100"
									:showText="false" height="15"></u-line-progress>
									<!-- <u-line-progress activeColor="rgba(4, 184, 243, 1)"
										:percentage="12"
										:showText="false" height="15"></u-line-progress> -->
							</view>
							
						</view>
					</view>
				</view>
				<view style="width:calc(100% - 166upx);" class="ml30">
					<view>
						<view class="card-shadow-box p20">
							<view class="flex-between">
								<view class="wper50">
									<view class="tc wper100">
										<view>前胎压</view>
									</view>
									<view class="flex-column-center mt30">
										<u-icon name="taiya1"
											:color="toFormatVal(drivingDataPoint.carFrontTirePressure,[0,3.5],1)<1.8?'#FD8C05':'rgb(4, 184, 243)'"
											size="32" :isShowIcon="false" customPrefix="iconfontbike iconbike"></u-icon>
										<view class="flex-row baseline mt10">
											<view class="f36 mr4">
												{{toFormatVal(drivingDataPoint.carFrontTirePressure,[0,3.5],1)}}
											</view>
											<view class="f20">bar</view>
										</view>
									</view>
								</view>
								<view class="plr30">
									<u-line direction="col" length="86"></u-line>
								</view>
								<view class="wper50">
									<view class="tc wper100">
										<view>后胎压</view>
									</view>
									<view class="flex-column-center mt30">
										<u-icon name="taiya1"
											:color="toFormatVal(drivingDataPoint.carRearTirePressure,[0,3.5],1)<1.8?'#FD8C05':'rgb(4, 184, 243)'"
											size="32" :isShowIcon="false" customPrefix="iconfontbike iconbike"></u-icon>
										<view class="flex-row baseline mt10">
											<view class="f36 mr4">
												{{toFormatVal(drivingDataPoint.carRearTirePressure,[0,3.5],1)}}
											</view>
											<view class="f20">bar</view>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="flex-row mt30">
							<view class="card-shadow-box p20 flex-column-center wper50 pb16">
								<view class="flex-align-center">
									<view>发动机温度</view>
								</view>
								<view class="flex-column-center mt30">
									<u-icon name="shuixiangwendu"
										:color="toFormatVal(drivingDataPoint.engineTemperature, [-40, 150], 0)>115?'#FD8C05':'rgb(4, 184, 243)'"
										size="32" :isShowIcon="false" customPrefix="iconfontbike iconbike"></u-icon>
									<view class="flex-row baseline mt10">
										<view class="f36 mr4">
											{{toFormatVal(drivingDataPoint.engineTemperature, [-40, 150], 0)}}
										</view>
										<view class="f20">°C</view>
									</view>
								</view>
							</view>
							<view class="card-shadow-box p20 flex-column-center wper50 ml30 pb16">
								<view class="flex-align-center">
									<view>节气门开度</view>
								</view>
								<view class="flex-column-center mt30">
									<u-icon name="jieqimenkaidu" color="rgb(4, 184, 243)" size="32" :isShowIcon="false"
										customPrefix="iconfontbike iconbike"></u-icon>
									<view class="flex-row baseline  mt10">
										<view class="f36 mr4">{{toFormatVal(drivingDataPoint.doorOpen, [0,100], 0)}}
										</view>
										<view class="f20">%</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		getSecondsUtil,
		getRangeVal
	} from "@/utils/utils.js"
	import {
		isUndefined
	} from "../../utils/mqtt.min";
	import {
		mapState
	} from 'vuex';

	export default {
		data() {
			return {
				lt:"<30"
			};
		},
		computed: {
			...mapState(["drivingDataPoint", "enduranceMileage","indexDataPoint"])
		},
		onShow() {
			uni.setKeepScreenOn({
				keepScreenOn: true,
				success() {
					console.log("设置成功");
				}
			});
		},
		methods: {
			numerRound(val) {
				let str = val + '';
				let lastNumber = parseInt(str.substring(str.length - 1));
				if (lastNumber < 5) {
					if (str.length > 1) {
						return parseInt(str.substring(0, str.length - 1) + "0");
					} else {
						return 0;
					}
				} else {
					if (str.length > 1) {
						return parseInt(str.substring(0, str.length - 1)) * 10 + 10;
					} else {
						return 10;
					}
				}
			},
			setNumerRound(val, arr, fix = 2) {
				let newval = this.toFormatVal(val, arr, fix);
				if (newval != '-') {
					return this.numerRound(newval);
				} else {
					return "-";
				}
			},
			toFormatVal(val, arr, fix = 2) {
				if (val == null || val === '') {
					return '-'
				}
				let n = getRangeVal(val, arr);
				return Number(n).toFixed(fix);
			}
		}
	};
</script>
<style lang="scss" scoped>
	.driving {
		position: relative;
	}



	.t-box {
		width: 356upx;
		height: 356upx;

		.cs {
			position: absolute;
			bottom: 60rpx;
		}
	}

	.t-box-small {
		width: 160upx;
		height: 160upx;
	}

	.t-box,
	.t-box-small {
		position: relative;
		justify-content: center;

		>image {
			position: absolute;
		}

		view {
			z-index: 11;
		}
	}

	.yh-box {
		.yh {
			position: absolute;
			left: 0;
			right: 0;
			top: 200upx;
			z-index: 1111;
			text-align: center;
		}

		// .card-shadow-box {
		// 	width: 226upx;
		// }

		::v-deep .u-line-progress__line {
			height: 120upx !important;
			border-bottom-right-radius: 0 !important;
			border-top-right-radius: 0 !important;
			border-radius: 0 !important;
		}

		::v-deep .u-line-progress__background {
			border-radius: 28upx !important;
			height: 100% !important;
			background-color: rgba(220, 38, 38, 0) !important;
		}

		.u-line-progress,
		::v-deep .u-line-progress {
			transform: rotate(270deg);
			border: 2upx solid #04B8F3 !important;
			height: 120upx !important;
			width: 362upx !important;
			border-radius: 28upx !important;
			position: absolute;
			left: -78upx;
			top: 200upx;
		}
	}
</style>
